import traceback
from ..output.output_go import OutGo

class DataFormatException(Exception):
    """不是能够处理的日期格式"""
    def __init__(self, err='Not illeagle Date Format'):
        Exception.__init__(self, err)


class BaseDateLackException(Exception):
    """抓取回的数据缺少必要数据异常 比如缺少 content title"""
    def __init__(self, err='Lack of base data'):
        Exception.__init__(self, err)


class DataBaseConnectFailedException(Exception):
    """数据库链接失败异常"""
    def __init__(self, err='Database Connect Failed!'):
        Exception.__init__(self, err)


class HttpConnectionFailedException(Exception):
    """数据请求最大已达最大尝试次数"""
    def __init__(self, url):
        Exception.__init__(self, 'Http Connect Failed! Url: ' + url)


class DatabaseOperationException(Exception):
    """需要操作的字段在数据库中不存在"""
    def __init__(self, val):
        Exception.__init__(self, 'Unknow Column: ' + val)


class ReadConfigFileException(Exception):
    """读取配置文件出错"""
    def __init__(self):
        Exception.__init__(self, 'Read Config Failed!')


class TableStructureKeyLackException(Exception):
    """数据库对应结构缺少关键信息错误"""
    def __init__(self, info):
        Exception.__init__(self, 'DateStructure key or type was lake, index: ' + str(info))


class TableStructureNoKeyException(Exception):
    """数据库中无对应字段"""
    def __init__(self,table, key):
        Exception.__init__(self, table, key)


class TableInsertColumnError(Exception):
    """向数据库插入列失败"""
    def __init__(self, table, key):
        Exception.__init__(self, 'Insert Column Error! table: ' + table + ' key: ' + key)


class WebTargetOutOfDateException(Exception):
    """网站抓取信息 过时 错误"""
    def __init__(self, info):
        Exception.__init__(self, 'Web Target Information OutOfDate: ' + str(info))


class ExceptionGo:
    @staticmethod
    def out_err(e=None):
        msg = traceback.format_exc()
        OutGo.pr(msg)
